<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>2_state属性简写</title>
  </head>
  <body>
    <!-- 准备号一个容器 -->
    <div id="test"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom，用于支持react dom操作 -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入babel，用于将jsx转为js -->
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <script type="text/babel">
      // 1. 创建组件
      class Weatcher extends React.Component {
        // constructor(props) {
        //   super(props)
        // this.state = { isHot: true }
        // this.switchWeather = this.switchWeather.bind(this)
        // }

        state = { isHot: true }

        render() {
          return <h2 onClick={this.switchWeather}>今天天气很{this.state.isHot ? '炎热' : '凉爽'}</h2>
        }

        // switchWeather() {
        //   this.setState({ isHot: !this.state.isHot })
        // }

        // 自定义方法--要用赋值语句形式+箭头函数
        switchWeather = () => {
          this.setState({ isHot: !this.state.isHot })
        }
      }

      // 2. 渲染组件到页面
      ReactDOM.render(<Weatcher />, document.getElementById('test'))
    </script>
  </body>
</html>
